///*
// * Copyright (c) 2018-2999 山东卯时信息科技有限公司 All rights reserved.
// *
// * https://www.gz-maoshi.com/
// *
// */
//
//package com.maoshi.shop.delivery.platform.controller;
//
//
//import com.maoshi.shop.bean.enums.OfflineHandleEventType;
//import com.maoshi.shop.bean.model.OfflineHandleEvent;
//import com.maoshi.shop.bean.model.Product;
//import com.maoshi.shop.bean.param.OfflineHandleEventAuditParam;
//import com.maoshi.shop.common.annotation.SysLog;
//import com.maoshi.shop.common.exception.MaoshiShopBindException;
//import com.maoshi.shop.seckill.platform.dto.SeckillProdDto;
//import com.maoshi.shop.security.platform.util.SecurityUtils;
//import com.maoshi.shop.service.OfflineHandleEventService;
//import com.maoshi.shop.service.ProductService;
//import lombok.AllArgsConstructor;
//import ma.glasnost.orika.MapperFacade;
//import org.springframework.http.ResponseEntity;
//import org.springframework.security.access.prepost.PreAuthorize;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Objects;
//
//
///**
// * 秒杀信息
// *
// * @author LGH
// * @date 2019-08-28 09:36:59
// */
//@RestController
//@AllArgsConstructor
//@RequestMapping("/platform/seckill")
//public class SeckillController {
//
//    private final SeckillService seckillService;
//
//    private final MapperFacade mapperFacade;
//
//    private final ProductService productService;
//
//    private final SeckillSkuService seckillSkuService;
//
//    private final OfflineHandleEventService offlineHandleEventService;
//
//    /**
//     * 分页查询
//     *
//     * @param page    分页对象
//     * @param seckill 秒杀信息1
//     * @return 分页数据
//     */
//    @GetMapping("/page")
//    public ResponseEntity<IPage<Seckill>> getSeckillPage(PageParam<Seckill> page, Seckill seckill) {
//        IPage<Seckill> seckillIPage = seckillService.getPlatformSeckillPage(page, seckill);
//        return ResponseEntity.ok(seckillIPage);
//    }
//
//    /**
//     * 通过id查询秒杀信息
//     *
//     * @param seckillId id
//     * @return 单个数据
//     */
//    @GetMapping("/info/{seckillId}")
//    public ResponseEntity<SeckillProdDto> getById(@PathVariable("seckillId") Long seckillId) {
//        Seckill seckill = seckillService.getSeckillById(seckillId);
//
//        SeckillProdDto dto = new SeckillProdDto();
//        dto.setSeckill(seckill);
//        dto.setSeckillSkus(seckillSkuService.listSeckillSkuBySeckillId(seckillId));
//        Product product = productService.getProductByProdId(seckill.getProdId());
//        dto.setProd(product);
//        return ResponseEntity.ok(dto);
//    }
//
//    /**
//     * 通过id使秒杀商品失效
//     *
//     * @param seckillId id
//     * @return 是否删除成功
//     */
//    @SysLog("使秒杀失效信息")
//    @PutMapping("/invalid/{seckillId}")
//    public ResponseEntity<Void> invalidById(@PathVariable Long seckillId) {
//        Seckill seckill = seckillService.getSeckillById(seckillId);
//        seckillService.invalidById(seckill);
//
//        productService.removeProductCacheByProdId(seckill.getProdId());
//        seckillSkuService.removeSeckillSkuCacheBySeckillId(seckill.getSeckillId());
//        seckillService.removeSeckillCacheById(seckill.getSeckillId());
//        return ResponseEntity.ok().build();
//    }
//
//    /**
//     * 通过id删除秒杀信息
//     *
//     * @param seckillId id
//     * @return 是否删除成功
//     */
//    @SysLog("删除秒杀信息")
//    @DeleteMapping("/{seckillId}")
//    public ResponseEntity<Void> removeById(@PathVariable Long seckillId) {
//        Seckill seckill = seckillService.getSeckillById(seckillId);
//
//        if (!Objects.equals(0, seckill.getStatus())) {
//            throw new MaoshiShopBindException("秒杀活动未失效，无法删除");
//        }
//        seckill.setIsDelete(1);
//        seckillService.updateById(seckill);
//        seckillSkuService.removeSeckillSkuCacheBySeckillId(seckill.getSeckillId());
//        return ResponseEntity.ok().build();
//    }
//
//    /**
//     * 通过活动id获取下线信息
//     */
//    @GetMapping("/getOfflineHandleEventBySeckillId/{seckillId}")
//    @PreAuthorize("@pms.hasPermission('platform:seckill:info')")
//    public ResponseEntity<OfflineHandleEvent> getOfflineHandleEventByDiscountId(@PathVariable("seckillId") Long seckillId) {
//        OfflineHandleEvent offlineHandleEvent = offlineHandleEventService.getProcessingEventByHandleTypeAndHandleId(OfflineHandleEventType.SECKILL.getValue(), seckillId);
//        return ResponseEntity.ok(offlineHandleEvent);
//    }
//
//    /**
//     * 下线活动
//     */
//    @PostMapping("/offline")
//    @PreAuthorize("@pms.hasPermission('platform:seckill:update')")
//    public ResponseEntity<Void> offline(@RequestBody OfflineHandleEvent offlineHandleEvent) {
//        Seckill seckill = seckillService.getSeckillById(offlineHandleEvent.getHandleId());
//        if (seckill == null) {
//            throw new MaoshiShopBindException("未找到该秒杀活动信息");
//        }
//        Long sysUserId = SecurityUtils.getSysUser().getUserId();
//        seckillService.offline(seckill, offlineHandleEvent.getOfflineReason(), sysUserId);
//
//        // 移除缓存
//        seckillService.removeSeckillCacheById(seckill.getSeckillId());
//        return ResponseEntity.ok().build();
//    }
//
//    /**
//     * 审核活动
//     */
//    @PostMapping("/auditSeckill")
//    @PreAuthorize("@pms.hasPermission('platform:seckill:update')")
//    public ResponseEntity<Void> auditSeckill(@RequestBody OfflineHandleEventAuditParam offlineHandleEventAuditParam) {
//        Long sysUserId = SecurityUtils.getSysUser().getUserId();
//        Seckill seckill = seckillService.getSeckillById(offlineHandleEventAuditParam.getHandleId());
//        if (seckill == null) {
//            throw new MaoshiShopBindException("未找到该秒杀活动信息");
//        }
//        seckillService.auditSeckill(offlineHandleEventAuditParam, sysUserId);
//
//        // 移除缓存
//        seckillService.removeSeckillCacheById(seckill.getSeckillId());
//        return ResponseEntity.ok().build();
//    }
//
//
//}
